import Router from 'koa-router'
import config from '../../config/index.js'

import redis from '../../utils/redis.js'

const DEVICE_PREFIX = 'webrtc:device:'
const ROOM_PREFIX = 'webrtc:room:'
const CALL_PREFIX = 'webrtc:call:'
const CONN_PREFIX = 'webrtc:conn:'

const router = new Router()
router.get('/metrics/summary', async (ctx) => {
  const roomKeys = await redis.keys(ROOM_PREFIX + '*')
  const callKeys = await redis.keys(CALL_PREFIX + '*')
  const connKeys = await redis.keys(CONN_PREFIX + '*')

  ctx.body = {
    rooms: roomKeys.length,
    calls: callKeys.length,
    connections: connKeys.length,
    websocket: {
      port: config.websocket.port,
      useSSL: config.websocket.useSSL
    }
  }
})

export default router


